package com.airS.task.fileMgr.common.response;

import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.annotation.JSONType;

import java.io.Serializable;

/**
 * 操作結果
 * Created by alan on 2017/3/9.
 */
@JSONType(orders = {"code", "msg", "data"})
public class BaseResponse<T> implements Serializable {
    private static final ResponseCode SUCCESS;
    private StatusCode code;
    private String msg;
    private T data;
    @JSONField(serialize = false)
    private String callback;

    public BaseResponse() {
        this.setCode(SUCCESS);
        this.msg = SUCCESS.msg();
    }

    public BaseResponse(T data) {
        this();
        this.data = data;
    }

    public BaseResponse(T data, String callback) {
        this(data);
        this.callback = callback;
    }

    public StatusCode getCode() {
        return this.code;
    }

    public void setCode(StatusCode code) {
        this.code = code;
        this.msg = code.msg();
    }

    public String getMsg() {
        return this.msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getCallback() {
        return this.callback;
    }

    public void setCallback(String callback) {
        this.callback = callback;
    }

    static {
        SUCCESS = ResponseCode.SUCCESS;
    }
}
